home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 6 / The Arsenal Files 6 (Arsenal Computer).ISO / prg_casm / jlvesa11.zip / JLVESA10.ASM < prev    next >
Assembly Source File  |  1995-11-14  |  8KB  |  376 lines

  1. ; This routine is part of VESA SVGA -library
  2. ;
  3. ; Copyright 1994 Johannes Lehtinen
  4. ; All rights reserved
  5.  
  6. model large,c
  7. p386
  8.  
  9. include "jlvesads.asm"
  10.  
  11. extrn vesa_repos_w:far
  12.  
  13. segment jlvesa10_TEXT USE16 'CODE'
  14. assume cs:jlvesa10_TEXT
  15.  
  16. ; void JVImage_Draw(JVSWord x, JVSWord y, JVUWord width, JVUWord height,
  17. ;                   void *image)
  18. ;
  19. ; Puts image to screen
  20.  
  21. ; Some information
  22.  
  23. bl_linesleft   dw ?  ; Lines left to draw
  24. bl_repolines   dw ?  ; Lines before next reposition
  25. bl_overflines  dw ?  ; Lines before next overflow
  26. bl_left        dw ?  ; Pixels outside the left border
  27. bl_up          dw ?  ; Pixels outside the upper border
  28. bl_right       dw ?  ; Pixels outside the right border
  29. bl_width       dw ?  ; Pixels on screen horizontally
  30.  
  31. proc JVImage_Draw far
  32.    public JVImage_Draw
  33.  
  34.    push  bp
  35.    mov   bp,sp
  36.    push  si
  37.    push  di
  38.    push  ds
  39.    push  es
  40.    push  fs
  41.  
  42.    mov   ax,JLVesa_Data
  43.    mov   fs,ax
  44.  
  45.    mov   [cs:bl_left],0
  46.    mov   [cs:bl_up],0
  47.    mov   [cs:bl_right],0
  48.  
  49.    ; Make sure the block is on screen
  50.  
  51.    cmp   [word ptr ss:bp+6],0
  52.    jge   short x_not_below
  53.  
  54.    ; X is less than 0
  55.  
  56.    xor   ax,ax
  57.    sub   ax,[ss:bp+6]
  58.    mov   [cs:bl_left],ax
  59.  
  60. x_not_below:
  61.    cmp   [word ptr ss:bp+8],0
  62.    jge   short y_not_below
  63.  
  64.    ; Y is less than 0
  65.  
  66.    xor   ax,ax
  67.    sub   ax,[ss:bp+8]
  68.    mov   [cs:bl_up],ax
  69.  
  70. y_not_below:
  71.  
  72.    ; Calculate pixels on screen at this point
  73.  
  74.    mov   ax,[ss:bp+10]
  75.    sub   ax,[cs:bl_left]
  76.    mov   [cs:bl_width],ax
  77.    mov   ax,[ss:bp+12]
  78.    sub   ax,[cs:bl_up]
  79.    mov   [cs:bl_linesleft],ax
  80.  
  81.    mov   ax,[ss:bp+6]
  82.    add   ax,[ss:bp+10]
  83.    cmp   [fs:Width],ax
  84.    jg    short width_not_above
  85.  
  86.    ; Wider than screen
  87.  
  88.    sub   ax,[fs:Width]
  89.    mov   [cs:bl_right],ax
  90.    mov   ax,[ss:bp+10]
  91.    sub   ax,[cs:bl_left]
  92.    sub   ax,[cs:bl_right]
  93.    mov   [cs:bl_width],ax
  94.  
  95. width_not_above:
  96.    mov   ax,[ss:bp+8]
  97.    add   ax,[ss:bp+12]
  98.    cmp   [fs:Height],ax
  99.    jg    short height_not_above
  100.  
  101.    ; Heigher than screen
  102.  
  103.    sub   ax,[fs:Height]
  104.    mov   bx,ax
  105.    mov   ax,[ss:bp+12]
  106.    sub   ax,[cs:bl_up]
  107.    sub   ax,bx
  108.    mov   [cs:bl_linesleft],ax
  109.  
  110.    ; Check that width or height is not negative
  111.  
  112. height_not_above:
  113.    cmp   [cs:bl_width],0
  114.    jle   end_of_block
  115.    cmp   [cs:bl_linesleft],0
  116.    jle   end_of_block
  117.  
  118.    ; Calculate absolute address of starting point
  119.  
  120.    xor   eax,eax              ; Calculate address of start of line
  121.    xor   ebx,ebx
  122.    mov   ax,[ss:bp+8]
  123.    add   ax,[cs:bl_up]
  124.    mov   bx,[fs:LWidth]
  125.    mul   ebx
  126.    mov   bx,[ss:bp+6]         ; Calculate address of starting point
  127.    add   bx,[cs:bl_left]
  128.    add   eax,ebx
  129.    add   eax,[fs:AStart]      ; Calculate address if scrolled
  130.    mov   edx,eax
  131.  
  132.    ; Initialize registers used
  133.  
  134.    mov   ax,[fs:WWSeg]
  135.    mov   es,ax
  136.    cld                        ; Direction forward
  137.  
  138.    ; Reposition window if necessary
  139.  
  140.    cmp   [fs:WAStart],edx
  141.    jbe   short not_bef_win
  142.    call  far vesa_repos_w
  143.    jmp   short go_drawing
  144.  
  145. not_bef_win:
  146.    mov   eax,[fs:WAStart]
  147.    add   eax,[fs:WSize]
  148.    cmp   edx,eax
  149.    jb    short go_drawing
  150.    call  far vesa_repos_w
  151.  
  152.    ; Calculate current offset
  153.  
  154. go_drawing:
  155.    mov   edi,edx
  156.    sub   edi,[fs:WAStart]
  157.  
  158.    ; Read DS:SI
  159.  
  160.    xor   eax,eax
  161.    mov   ax,[cs:bl_up]
  162.    xor   ebx,ebx
  163.    mov   bx,[ss:bp+10]        ; EBX is width of image
  164.    push  edx
  165.    mul   ebx
  166.    pop   edx
  167.    mov   bx,[cs:bl_left]
  168.    add   eax,ebx              ; EAX is number of bytes to add to SI
  169.  
  170.    xor   esi,esi
  171.    mov   si,[ss:bp+14]        ; Read SI and make addition
  172.    add   esi,eax
  173.  
  174.    mov   ebx,esi
  175.    shr   ebx,4
  176.    and   esi,0fH
  177.    mov   ax,[ss:bp+16]        ; Read DS and make addition
  178.    add   ax,bx
  179.    mov   ds,ax
  180.  
  181.    ; Drawing loop
  182.  
  183.    ; First calculate, how many lines can be drawn without address overflow.
  184.    ; Check both ES:DI and DS:SI.
  185.  
  186.    ; First check how many lines before window reposition
  187.  
  188. draw_loop:
  189.    cmp   [cs:bl_linesleft],0
  190.    je    end_of_block
  191.  
  192.    mov   eax,[fs:WAStart]
  193.    add   eax,[fs:WSize]
  194.    dec   eax
  195.    sub   eax,edx
  196.    xor   ebx,ebx
  197.    mov   bx,[fs:LWidth]
  198.    push  edx
  199.    xor   edx,edx
  200.    div   ebx
  201.    pop   edx
  202.  
  203.    cmp   [cs:bl_linesleft],ax ; Check if fewer lines left than possible to draw on the page
  204.    jae   short jump_0
  205.    mov   ax,[cs:bl_linesleft]
  206.  
  207. jump_0:
  208.    mov   [cs:bl_repolines],ax
  209.  
  210.    ; Then check how many lines before DS:SI overflow
  211.  
  212.    mov   eax,10000H
  213.    sub   eax,esi
  214.    push  edx
  215.    xor   edx,edx
  216.    xor   ebx,ebx
  217.    mov   bx,[fs:LWidth]
  218.    div   ebx
  219.    pop   edx
  220.  
  221.    cmp   [cs:bl_linesleft],ax ; Check if fewer lines left than possible to draw before overflow
  222.    jae   short jump_1
  223.    mov   ax,[cs:bl_linesleft]
  224.  
  225. jump_1:
  226.    mov   [cs:bl_overflines],ax
  227.  
  228.    ; Start drawing as many lines as possible before
  229.    ; First check if normal lines can be drawn next at all
  230.  
  231. draw_line:
  232.    cmp   [cs:bl_overflines],0
  233.    je    overf_check
  234.  
  235.    cmp   [cs:bl_repolines],0
  236.    je    short special_line
  237.  
  238.    mov   cx,[cs:bl_width]     ; Width of the block
  239.    cmp   cx,3
  240.    jb    short jump_4
  241.  
  242.    test  di,1                 ; Check if need to write one byte
  243.    jz    short jump_2
  244.    movsb
  245.    dec   cx
  246.  
  247. jump_2:
  248.    test  di,2                 ; Check if need to write two bytes
  249.    jz    short jump_3
  250.    movsw
  251.    sub   cx,2
  252.  
  253. jump_3:
  254.    mov   bx,cx                ; Write four bytes at time
  255.    shr   cx,2
  256.    jz    short jump_4
  257.  
  258.    rep   movsd
  259.    mov   cx,bx
  260.  
  261. jump_4:
  262.    test  cx,2
  263.    jz    short jump_5
  264.    movsw
  265.  
  266. jump_5:
  267.    test  cx,1
  268.    jz    short jump_6
  269.    movsb
  270.  
  271. jump_6:
  272.    add   di,[fs:LWidth]       ; Move to the start of next line
  273.    sub   di,[cs:bl_width]
  274.  
  275.    xor   ecx,ecx
  276.    mov   cx,[fs:LWidth]
  277.    add   edx,ecx
  278.    add   si,[cs:bl_right]
  279.    add   si,[cs:bl_left]
  280.  
  281.    dec   [cs:bl_repolines]
  282.    dec   [cs:bl_overflines]
  283.    dec   [cs:bl_linesleft]
  284.    jmp   short draw_line
  285.  
  286.    ; Draw line, which is between two pages
  287.  
  288. special_line:
  289.    mov   ecx,[fs:WAStart]     ; Calculate how line is divided
  290.    add   ecx,[fs:WSize]
  291.    sub   ecx,edx
  292.    cmp   [cs:bl_width],cx
  293.    jbe   short line_on_current   ; Line on current page
  294.  
  295.    ; Line is divided on both pages
  296.  
  297.    mov   bx,[cs:bl_width]     ; BX = length of the line on next page
  298.    sub   bx,cx
  299.    rep   movsb                ; Draw line on current page
  300.  
  301.    xor   ecx,ecx
  302.    mov   cx,[fs:LWidth]
  303.    add   edx,ecx              ; Switch on next page
  304.    call  far vesa_repos_w
  305.    mov   edi,edx              ; Calculate new DI
  306.    xor   ecx,ecx
  307.    mov   cx,[fs:LWidth]
  308.    sub   edi,ecx
  309.    xor   ecx,ecx
  310.    mov   cx,[cs:bl_width]
  311.    add   edi,ecx
  312.    sub   edi,[fs:WAStart]
  313.    sub   di,bx
  314.  
  315.    mov   cx,bx                ; Draw line on next page
  316.    rep   movsb
  317.  
  318.    add   di,[fs:LWidth]       ; Move on the next line
  319.    sub   di,[cs:bl_width]
  320.  
  321.    add   si,[cs:bl_right]
  322.    add   si,[cs:bl_left]
  323.  
  324.    dec   [cs:bl_linesleft]
  325.    jnz   draw_loop
  326.    jmp   short end_of_block
  327.  
  328.    ; Line is on current page
  329.  
  330. line_on_current:
  331.    mov   cx,[cs:bl_width]     ; Draw line on this page
  332.    rep   movsb
  333.  
  334.    xor   ecx,ecx
  335.    mov   cx,[fs:LWidth]
  336.    add   edx,ecx
  337.    call  far vesa_repos_w
  338.    mov   edi,edx              ; Move to start of next line
  339.    sub   edi,[fs:WAStart]
  340.  
  341.    add   si,[cs:bl_right]
  342.    add   si,[cs:bl_left]
  343.  
  344.    dec   [cs:bl_linesleft]
  345.    jnz   draw_loop
  346.    jmp   short end_of_block
  347.  
  348.    ; Handle DS:SI overflow
  349.  
  350. overf_check:
  351.    mov   ax,si
  352.    shr   ax,4
  353.    mov   bx,ds
  354.    add   ax,bx
  355.    mov   ds,ax
  356.    and   si,0fH
  357.    jmp   draw_loop
  358.  
  359.    ; End drawing
  360.  
  361. end_of_block:
  362.    pop   fs
  363.    pop   es
  364.    pop   ds
  365.    pop   di
  366.    pop   si
  367.    pop   bp
  368.    retf
  369.  
  370. endp JVImage_Draw
  371.  
  372. ends
  373.  
  374. end
  375.  
  376.